import time
class Solution:
    def search(self, nums, target) -> int:
        
        length = len(nums)
        left,right = 0,length - 1
        mid = int((left + right) / 2)
        while left <= right:
            mid = int((left + right) / 2)
            if nums[mid] == target:
                return mid

            if nums[mid] >= nums[left]:
                if nums[left] <= target <= nums[mid]:
                    right = mid - 1
                else:
                    left = mid + 1
            # 右半段有序
            else:
                if nums[mid] <= target <= nums[right]:
                    left = mid + 1
                else:
                    right = mid - 1
                
        return -1

# s = Solution()
# nums = [4,5,6,7,0,1,2]
# target = 2

# print(s.search(nums,target))